<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>添加商品照片</title>
</head>
<link href="/css/bootstrap.css" rel="stylesheet">
<script src="/js/jquery-2.1.4.js"></script>
<script src="/js/vue.js"></script>
<script src="/js/bootstrap.js"></script>
<body>
    <form>
        <input type="file" id="file1" name="space" placeholder="请添加封面图片，封面只能添加一张" accept="image/*">
        <input type="button" onclick="uploadSingle()" value="上传封面">
        <hr>
        <input type="file" id="file" multiple="multiple" placeholder="选择图片">
        <input type="button" onclick="uploadImages()" value="上传商品介绍图片">
        <hr>
        <input type="file" id="fileinfo" multiple="multiple" placeholder="选择商品详情图片">
        <input type="button" onclick="uploadInfoImages()" value="上传商品详情图片">
    </form>
<script>
    function uploadImages() {
        var formData = new FormData();
        for(var i=0;i<$("#file")[0].files.length;i++) {  //循环获取上传个文件
            formData.append("file", $("#file")[0].files[i]);
        }
        formData.append("status",2);//此处可以添加一个参数和图片一起上传
        $.ajax({
            "url": "/product/addProductImages",
            "data" : formData,
            "dataType":"json",
            "type": "post",
            "contentType" : false, //上传文件一定要是false
            "processData":false,
            "success" : function(obj) {
                alert("上传成功！");
            }
        });
    }
    function uploadInfoImages() {
        var formData = new FormData();
        for(var i=0;i<$("#fileinfo")[0].files.length;i++) {  //循环获取上传个文件
            formData.append("file", $("#file")[0].files[i]);
        }
        $.ajax({
            "url": "/product/addProductInfoImages",
            "data" : formData,
            "dataType":"json",
            "type": "post",
            "contentType" : false, //上传文件一定要是false
            "processData":false,
            "success" : function(obj) {
                alert("上传成功！");
            }
        });
    }
   function uploadSingle() {
       var formData = new FormData();
       formData.append("file", $("#file1")[0].files[0]);
       formData.append("status", 1);//此处可以添加一个参数和图片一起上传
       $.ajax({
           "url": "/product/addProductImage",
           "data": formData,
           "dataType": "json",
           "type": "post",
           "contentType": false, //上传文件一定要是false
           "processData": false,
           "success": function (obj) {
               alert("上传成功");
           }
       })
   }

</script>
</body>
</html>